home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcclib.zip / DEMO2.C < prev    next >
Text File  |  1989-02-11  |  2KB  |  104 lines

  1. /**************************************************************
  2.                       WindowListerDemo
  3. **************************************************************/
  4. #include "tcclib.h"
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <mem.h>
  9. #include <conio.h>
  10.  
  11. typedef struct {
  12.     char Path[64];
  13.     char Name[13];
  14.     long Size;
  15. } FileRec;
  16.  
  17. FileRec File[100];
  18.  
  19. int NumRecs = 80;
  20.  
  21. int StoreFile( FileStruc *fp, char *s )
  22. /* support function for ScanTree */
  23. {
  24.      static int count = 0;
  25.  
  26.      if ( count < 80 ) {
  27.          strcpy( File[count].Name, FileName( fp ) );
  28.          strcpy( File[count].Path, s );
  29.          File[count].Size = fp->Size;
  30.          count++;
  31.      }
  32.      return( 1 );
  33. }
  34.  
  35. void DisplayDemo( int ndx )
  36. {
  37.     char s[64];
  38.     sprintf( s, "%s%s", File[ndx].Path, File[ndx].Name );
  39.     SayF("%-32s %8ld", s, File[ndx].Size );
  40. }
  41.  
  42. void ClearScreenDemo( void )
  43. {
  44.     BlockErase( 20, 5, 60, 20 );
  45. }
  46.  
  47. Compare( FileRec *a, FileRec *b )
  48. {
  49.     if ( 0 != strcmp( a->Path, b->Path ) )
  50.         return( strcmp( a->Path, b->Path ) );
  51.     return( strcmp( a->Name, b->Name) );
  52. }
  53.  
  54. int CharHandlerDemo( int ch, int ndx, int line )
  55. /* note that this does not have to handle the ESC key, since we told
  56.    WindowLister to exit when that key is pressed.
  57.  
  58.    Note:  The "line" parameter is not used in this demo function.  It is
  59.           only needed if you want to determine where (on the screen) the
  60.           item is that is currently highlighted.
  61. */
  62.  
  63. {
  64.     char temp[10];
  65.     int i = line;  /* this is to get rid of the warning message */
  66.  
  67.     switch( ch ) {
  68.         case F1:
  69.             Accept( 15, 23, "How many to jump (may be negative) : ", temp, 8 );
  70.             i = atoi( temp );
  71.             BlockErase( 15, 23, 65, 23 );
  72.             if ( ndx + i > NumRecs || ndx + i < 0 )
  73.                 return( ndx );
  74.             return( ndx + i );
  75.         case F4:
  76.             qsort( &File, NumRecs, sizeof( FileRec ), Compare );
  77.             return( ndx );
  78.         case DEL:
  79.             for (i=ndx; i<NumRecs; ++i)
  80.                 memcpy( &File[i], &File[i+1], sizeof( FileRec ) );
  81.             NumRecs--;
  82.             return( ndx );
  83.     }
  84.     return( ndx ); /* just in case the key wasn't one of the above */
  85. }
  86.  
  87. void WindowListerDemo()
  88. {
  89.     char Drive[5];
  90.  
  91.     clrscr();
  92.     Accept( 5, 5, "Drive : ", Drive, 1 );
  93.     strcat( Drive, ":\\" );
  94.     AtSay( 30, 10, "Scanning for files ... " );
  95.     ScanTree( Drive, "*.*", StoreFile );
  96.  
  97.     ExplodeBox( 19, 4, 61, 21 );
  98.     Center( 25, "F1=Jump      F4=Sort      DEL=Delete      ESC=Quit" );
  99.     WindowLister( 20, 5, 60, 20, ESC, &NumRecs, 0,
  100.         CharHandlerDemo,
  101.         ClearScreenDemo,
  102.         DisplayDemo );
  103. }
  104.